import Vue from 'vue';
import moment from 'moment';
import App from './App';
import router from './router';
import { ACCESS_TYPE } from '@/constants';
// 引入lke统一渲染插件
import lkeComponent from 'lke-component';

Vue.use(lkeComponent);
const vhtml = window.vhtml;
Vue.use(vhtml);
vhtml.install(Vue);

try {
    let iconpath = 'https://cdn3.codesign.qq.com/icons/XzKaDZdEa7j2GPL/latest/iconfont.js';
    vhtml.Icon.setDefaultRemoteSrc && vhtml.Icon.setDefaultRemoteSrc(iconpath);
} catch (e) {
    console.log('load remote icon error');
}

Vue.config.productionTip = false;
Vue.prototype.moment = moment;

router.beforeEach((to, from, next) => {
    document.title = to.meta.title || 'AI助手';
    if (to.name && window.$initType !== to.name) {
        window.location.reload();
    }
    next();
});

let webIMType; // 后端ws识别的端类型
let webIMSource; // 前端区分UI交互的端类型

webIMType = [5];
window.$initTypeKey = 5;
webIMSource = 'client';

Vue.prototype.webIMSource = webIMSource;

Object.defineProperty(window, 'userType', {
    writable: false,
    enumerable: false,
    configurable: false,
    value: 2
});

window.$initType = 'ChatDemo';


if (ACCESS_TYPE === 'ws') {
    (async () => {
        let mixin = await import('@/manage/index');
        Vue.mixin(mixin);
        /* eslint-disable no-new */
        new Vue({
            el: '#app',
            router,
            render(h) {
                return h(App);
            }
        }).$mount('#app');
    })();
} else {
    (async () => {
        let sseMixin = await import('@/manage/sse');
        Vue.mixin(sseMixin);
        /* eslint-disable no-new */
        new Vue({
            el: '#app',
            router,
            render(h) {
                return h(App);
            }
        }).$mount('#app');
    })();
}

